<?php include_once "ra_global.php";
$wish=$db->ig2_want('mae_wish_list','id='.$_GET['wishid']);
if(!$wish) tellgoto('','user.php');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,target-densitydpi=high-dpi,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<link href="images/m.css" rel="stylesheet" type="text/css" />
<script src="inc/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="inc/ajaxfileupload.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js" type="text/javascript"></script>
<script language="javascript">
function onBridgeReady(){
	WeixinJSBridge.call('hideOptionMenu');
}

if (typeof WeixinJSBridge == "undefined"){
	if( document.addEventListener ){
		document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
	}else if (document.attachEvent){
	document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
	document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
	}
}else{
	onBridgeReady();
}
</script>
<title>心愿单</title>
</head>
<?php 

if($wish['status']==0){?>
<body>
<div class="container">
    <div class="p5">
    	<img class="p5bg bg" src="images/p5bg.jpg">
        <img class="bt" id="p5_1" src="images/p5_1.jpg" onClick="act()">
        <script>
			document.getElementById("p5_1").addEventListener("touchstart", touchStartp5_1, false);
			document.getElementById("p5_1").addEventListener("touchend", touchEndp5_1, false);
			function touchStartp5_1(event){
				startX = event.touches[0].clientX;
				document.getElementById('p5_1').src='images/p5_1_h.jpg';	
			}
			function touchEndp5_1(event){
				endX = event.changedTouches[0].clientX;
				document.getElementById('p5_1').src='images/p5_1.jpg';
			}	
		</script>
        <img class="bt" id="p5_2" src="images/p5_2.png">
        <img class="bt" id="p5_3" src="images/p5_3.png">
        <img class="bt" id="p5_4" src="images/p5_4.png">
        <textarea class="bt" id="p5text" placeholder="我想要..." >
        </textarea>
        <input id="fileUpload" type="file" name="fileUpload" accept="image/*" onChange="return ajaxFileUpload('fileUpload')" />
        <img src="images/wishsucc.png" id="success" style="width:100%; position:absolute; top:0; left:0; display:none; z-index:50"/>
        <img src="images/wishbt.jpg" onClick="wx.closeWindow()" id="successbt" style="position:absolute; display:none; z-index:51"/>
        <script>
			document.getElementById("successbt").addEventListener("touchstart", touchStartsuccessbt, false);
			document.getElementById("successbt").addEventListener("touchend", touchEndsuccessbt, false);
			function touchStartsuccessbt(event){
				startX = event.touches[0].clientX;
				document.getElementById('successbt').src='images/wishbt_h.jpg';	
			}
			function touchEndsuccessbt(event){
				endX = event.changedTouches[0].clientX;
				document.getElementById('successbt').src='images/wishbt.jpg';
			}	
		</script>
    </div>
</div>
<?php
}else{
?>
<img src="images/opnioned.jpg" width="100%"/>
<?php
}
?>
<script type="text/javascript">

//ajax 上传
var filename='';
function act(){
	if(trim($('#p5text').val())!=''){
		$.ajax({
			url:"ra_ajax_wish.php",
			data:{
				id:<?php echo $_GET['wishid']?>,
				image:filename,
				content:$('#p5text').val()
			},
			type:'POST',
			success: function(){
				$('#success').show();
				$('#successbt').show();
			},
			error:function(){
			},
		});
	}else{
		alert('请填写心愿');
		$('#p5text').focus();
	}
}
function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g, "");
}
function ajaxFileUpload(fileUploadId) {
	$.ajaxFileUpload({
		url:'doajaxfileupload.php?n='+fileUploadId,//用于文件上传的服务器端请求地址
		secureuri:false,//是否需要安全协议，一般设置为false
		fileElementId:fileUploadId,//文件上传域的ID
		dataType:'json',//返回值类型 一般设置为json
		//服务器成功响应处理函数
		success:function(data,status){
			if(typeof(data.error)!='undefined'){
				if(data.error!=''){
					alert(data.error);
				}else{
					alert(data.msg);
				}
			}else{
				if(data.msg=='upload success'){	
					$("#p5_2").hide();
					filename=data.n;
					if((data.w/data.h)>(532/397)){
						var h=data.h*532/data.w/p;
						$("#p5_3").width(532/p).height(h).css({left:(x-532/p)/2+'px',top:272/p+((397/p-h)/2)+'px'});
					}else{
						var w=data.w*397/data.h/p;
						$("#p5_3").width(w).height(397/p).css({left:(x-w)/2+'px',top:272/p+'px'});
					}
					$("#p5_3").attr("src","logo/"+data.n);
				}else{
					if(data.msg=='Exceed the limit size'){
						alert('请上传小于4M的文件');
					}else if(data.msg=='The suffix is not legal'){
						alert('请上传jpg或者png的图片');
					}else{
						alert(data.msg+'上传失败，请重新上传');
					}
					$("#fileUpload,#p5_2").show();
				}
			}
		},
		//服务器响应失败处理函数
		error:function(data,status,e){
			alert(e);
		}
	})
	return false;
}

var x,y,p;
$(document).ready(function() {
	x=parseInt(window.innerWidth);
	y=parseInt(window.innerHeight);
	p=720/x;
	getWidth();
	
	$('#p5_4').click(function(){
		$('#p5_4').hide();
		$('#p5text').focus();
	});
	
});	

function getWidth(){
	$('.p1,.p2,.p3,.p4,.container,.bg').width(x);
	$('.p1,.p2,.p3,.p4,.p5,.p6,.p7,.p8').css({left:0,top:0});
	//p2
	$('#p5_1').width(531/p).height(77/p).css({left:(x-533/p)/2+'px',top:823/p+'px'});
	$('#p5_2').width(123/p).height(94/p).css({left:(x-123/p)/2+'px',top:441/p+'px'});
	$('#p5_3').width(532/p).height(397/p).css({left:(x-532/p)/2+'px',top:272/p+'px'});
	$('#p5_4').width(532/p).height(125/p).css({left:(x-532/p)/2+'px',top:679/p+'px'});
	$('#p5text').css({left:(x-532/p)/2+'px',top:679/p+'px',width:532/p+'px',height:125/p+'px',fontSize:24/p+'px'});
	$('#fileUpload').width(532/p).height(397/p).css({left:(x-532/p)/2+'px',top:272/p+'px'});
	//$('#fileUpload').css({left:(x-123/p)/2+'px',top:441/p+'px',width:123/p+'px',height:94/p+'px'});
	$('#successbt').css({width:134/p+'px',left:293/p+'px',top:630/p+'px'});
}
</script>
</body>
</html>
